interface IPaginationScope extends ng.IScope {
    // 车辆ID；

    pageList: number[]
    currentPage: number;
    totalItem: number;
    changeTo: (curPage: number) => void;
    pageChanged: (cur) => void;
    isFirst: boolean;
    isLast: boolean;
    itemsPerPage: number;

}


function tmsPagination($ngBootbox: BootboxService): ng.IDirective {
    return {
        restrict: 'E',
        templateUrl: './src/directives/tms-pagination/tms-pagination.html',
        transclude: true,
        scope: {

            currentPage: "=",
            totalItem: "=",
            pageChanged: "&",
            itemsPerPage: "="
        },
        link: ($scope: IPaginationScope) => {
            
           
            $scope.changeTo =  (curPage)=> {

                if((curPage>=1)&&!(curPage>$scope.pageList.length)){
                    $scope.pageChanged({ currentPages: curPage })
                }
                
            };

            $scope.$watch('totalItem',  (newVal :number, oldVal:number) =>{
                $scope.pageList=[]
                var totalPages:number = Math.ceil(newVal/ $scope.itemsPerPage);

                for(var k=0;totalPages>k;k++){
                    $scope.pageList.push(k+1);
                }
            });

            $scope.$watch('itemsPerPage', function (newVal:number, oldVal:number) {
                $scope.pageList=[]
                var totalPages:number = Math.ceil($scope.totalItem/ newVal);

                for(var k=0;totalPages>k;k++){
                    $scope.pageList.push(k+1);
                }

            })






        }

    }
}


tmsPagination['$inject'] = ["$ngBootbox"]
angular.module('tmsPagination', []).directive('tmsPagination', tmsPagination);